#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Brief:        python file
# Author:       Aragon<zmule@163.com>
# Last Change:  2007-11-28 11:35:01
# Version:      0.1

import wx
import sys
from TermsDict import *
from Term import *
from Weight import *
from google import *

sys.path.insert(0, '..')

class wxApp(wx.App):
    def OnInit(self):
        return True

class Frame(wx.Frame):
    def __init__(self):
        super(Frame, self).__init__(None, -1, '基于用户兴趣的搜索', size=(800,800))
        self.init()
        
    def init(self):
        import meide
        self.box = box = meide.VBox(padding=4)
        group = meide.SimpleGrid(padding=3)
        group.add('关键词', meide.Text('term'), 'txtTerm')
        group.add('下载网页', meide.MultiText(''), 'txtWeb')
        group.add('兴趣库匹配', meide.MultiText(''), 'txtInterest')
        group.add('兴趣网页', meide.MultiText(''), 'txtInterstWeb')
        box.add(group)
        
        cbox = meide.HBox(padding=5)
        cbox.add(meide.Button('搜索下载'), 'btnDown').bind('click', self.OnClickDown)
        cbox.add(meide.Button('匹配'), 'btnInterest').bind('click', self.OnClickInterest)
        cbox.add(meide.Button('兴趣搜索'), 'btnSearch').bind('click', self.OnClickSearch)
        cbox.add(meide.Button('Cancel'), 'btnCancel').bind('click', self.OnClose)
        box.add(cbox, flag=wx.ALIGN_CENTER)

        meide.create(self, box, fit=2)
        
    def OnClickDown(self, event):
        sh = SearchHtml()
        termlist = self.box.find('txtTerm').GetValue().split()
        sh.search('+'.join(termlist))
        self.box.find('txtWeb').SetValue(str(sh.findlist))

    def OnClickInterest(self, event):
        pass
    
    def OnClickSearch(self, event):
        pass
        
    def OnClose(self, event):
        self.Close()

if __name__ == '__main__':
    wxApp = wxApp(0)
    frame = Frame()
    frame.Show()
    wxApp.SetTopWindow(frame)
    wxApp.MainLoop()
